<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{$Think.config.site.title} - 产品续费</title>
    <meta name="keywords" content="{$Think.config.site.keywords}">
    <meta name="description" content="{$Think.config.site.description}">
    <link href="{$Think.config.site.resource_url}css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/animate.css" rel="stylesheet">    
    <link href="css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/style.css?v=4.1.0" rel="stylesheet">
    <style type="text/css">#listtable .fa {cursor: pointer;color: #1ab394; margin-right: 1em;}</style>
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content  animated fadeInRight article">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>{:lang('产品订单列表')}</h5>
                    </div>
                    <div class="ibox-content">
                         <div class="table-responsive">
                            <table class="table table-striped" id="listtable">
                                <thead>
                                    <tr>
                                        <th>{:lang('订单名称')}</th>
                                        <th>{:lang('购买版本')}</th>
                                        <th>{:lang('版本号')}</th>
                                        <th>{:lang('应付金额')}</th>
                                        <th>{:lang('实付金额')}</th>
                                        <th>{:lang('购买数量')}</th>
                                        <th>{:lang('到期时间')}</th>
                                        {if condition="($v['pay_status'] neq 1) and ($v['new_expiration_date'] neq 0)"}<th>{:lang('新到期时间')}</th> {/if}
                                        <th>{:lang('状态')}</th>
                                        <th>{:lang('操作')}</th>
                                    </tr>
                                    <?php if(isset($v)){?>
                                    <tr>
                                        <td>{:lang('智能柜软件服务费用')}</td>
                                        <td>{$v.vname}</td>
                                        <td>{$v.vision}</td>
                                        <td>{$v.payable_amount} 元</td>
                                        <td>{$v.real_amount} 元</td>
                                        <td>{$v.nums}</td>
                                        <td>{$v.old_expiration_date |date="Y-m-d",###}</td>
                                        {if condition="($v['pay_status'] neq 1) and ($v['new_expiration_date'] neq 0)"}<td>{$v.new_expiration_date |date="Y-m-d",### }</td>{/if}
                                        <td>{if condition="$v['pay_status'] eq 1"} 正常 {else /} <span class="btn btn-xs btn-danger">{:lang('未支付')}</span> {/if}</td>
                                        <td>{if condition="($v['pay_status'] eq 1) and ($ver['free'] eq 0)"}<span class="btn btn-xs btn-primary" id="renew">{:lang('续费')}</span>{elseif condition="$ver['free'] eq 1" /} <span class="btn btn-xs">{:lang('请咨询管理员')}</span>{else /}<span class="btn btn-xs btn-primary change" id="onbtn" data-id="{$v.id}">{:lang('确认支付')}</span> {/if}</td>
                                    </tr>
                                    <?php } else{ ?>
                                    <tr>
                                        <td colspan="8" text-align="center"> {:lang('暂无交易记录')} </td>
                                        <td><span class="btn btn-xs btn-primary">{:lang('续费')}</span></td>
                                    </tr>
                                    <?php } ?>
                                    <tr class="text-center" id="pay" style="display: none;">
                                        <td colspan="10">
                                            <img src="" alt="" id="qrcode" width="250px">
                                            <div><button type="button" class="btn btn-primary" id="onpay" data-id="{$v.id}">{:lang('确认已支付')}</button></div>
                                        </td>
                                    </tr>
                                    <tr style="border:0px;">
                                        <td colspan="10" style="height: 50px;border:0px;"">&nbsp;</td>
                                    </tr>
                                    <tr id="xufei" style="display: none">
                                        <form action="" class="form-horizontal" method="post" id="myfoms">
                                             <td colspan="2" style="border:0px;">
                                                 {:lang('版本')}
                                                <input type="text" class="form-control" value="{$v.vname} {$v.vision}" disabled="true" id="" style="width: 80%; display: inline-table;">
                                             </td>
                                             <td colspan="2" style="border:0px;">{:lang('金额')} <input id="price" class="form-control" type="text" value="{$v.price}" disabled="true" style="width: 80%; display: inline-table;"></td>
                                             <td colspan="2" style="border:0px;">{:lang('续费时长')}
                                                <select class="form-control" id="times" name="endtime" style="width:60%; display: inline-table;">
                                                    <option value="">{:lang('请选择时长')}</option>
                                                    <option value="12">12{:lang('月')}(1{:lang('年')})</option>
                                                    <option value="24">24{:lang('月')}(2{:lang('年')})</option>
                                                    <option value="36">36{:lang('月')}(3{:lang('年')})</option>
                                                    <option value="48">48{:lang('月')}(4{:lang('年')})</option>
                                                    <option value="60">60{:lang('月')}(5{:lang('年')})</option>
                                                </select>
                                             </td>
                                             <input type="hidden" name="dq" value="{$v.old_expiration_date}">
                                             <td colspan="2" style="border:0px;"><h3 style="font-weight:100;">{:lang('总金额')}：<span id="totalAmount" style="color:#ff0000;">0</span> {:lang('元')}</h3></td>
                                             <td colspan="2" style="border:0px;"><button type="button" class="btn btn-primary" id="queren" data-id="{$v.id}">{:lang('提交')}</button></div></td>
                                         </form>
                                    </tr>
                                </thead>
                            </table>
                         </div>   
                    </div>
                    <div class="ibox-title">
                        <h5>{:lang('历史订单记录')}</h5>
                    </div>
                    <div class="ibox-content">
                        <div class="table-responsive">
                            <table class="table table-striped" id="listtable">
                                <thead>
                                    <tr>
                                        <th>{:lang('订单号')}</th>
                                        <th>{:lang('版本名称')}</th>
                                        <th>{:lang('版本号')}</th>
                                        <th>{:lang('购买数量')}</th>
                                        <th>{:lang('应付金额')}</th>
                                        <th>{:lang('实际支付')}</th>
                                        <th>{:lang('支付状态')}</th>
                                        <th>{:lang('到期时间')}</th>
                                        <th>{:lang('创建时间')}</th>
                                    </tr>
                                </thead>
                                <tbody>
                                <?php if(isset($list)){ ?>
                                {volist name="list" id="vo"}
                                    <tr>
                                        <td>{$vo.order_no}</td>
                                        <td>{$vo.vname}</td>
                                        <td>{$vo.vision}</td>
                                        <td>{$vo.nums}</td>
                                        <td>{$vo.payable_amount}</td>
                                        <td>{$vo.real_amount}</td>
                                        <td>已支付</td>
                                        <td>{$vo.old_expiration_date|date="Y-m-d",###}</td>
                                        <td>{$vo.create_time|date="Y-m-d H:i:s",###}</td>
                                    </tr>
                                {/volist}
                                <?php }else{ ?>
                                    <tr>
                                        <td colspan="7" text-align="center"> {:lang('暂无交易记录')} </td>
                                    </tr>
                                <?php } ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="{$Think.config.site.resource_url}js/jquery.min.js?v=2.1.4"></script>
    <script src="{$Think.config.site.resource_url}js/bootstrap.min.js?v=3.3.5"></script>
    <script src="{$Think.config.site.resource_url}js/plugins/peity/jquery.peity.min.js"></script>
    <script src="{$Think.config.site.resource_url}js/plugins/iCheck/icheck.min.js"></script>
    <script src="{$Think.config.site.resource_url}js/plugins/layer/layer.js"></script>
    <script type="text/javascript">
    $(function(){
        $('#times').change(function(){
            var timenum = $('#times').val();
            var price = $('#price').val();
            var totalAmount = timenum * price;
            $('#totalAmount').html(totalAmount);
        });
        $(document).on('click','#onbtn',function(){
            var id = $(this).data('id');
            layer.confirm("{:lang('确定要支付?')}", {
                    btn: ["{:lang('确定')}","{:lang('取消')}"], //按钮
                    shade: false //不显示遮罩
                },
                function(){
                   $.ajax({
                        type : 'POST',
                        url  : '<?php echo \think\Request::instance()->root(); ?>/ausagent/Initialization/onpay',
                        dataType : 'json',
                        data : {id:id},
                        async : false,
                        success : function(result){
                            if(0 == result.code){
                                layer.msg();
                                $('#pay').show();
                                $("#onbtn").attr('id','newbtn');
                                $('#qrcode').attr('src',result.msg);
                            }else if(1 == result.code){
                                window.location.reload();
                            }else{
                                layer.msg(result.msg, {icon: 5});
                            }
                        },
                        error : function(){
                            layer.msg("{:lang('服务器错误！请稍后重试')}", {icon: 2});
                        }
                    })  
                },
                function(){

                });
           
        });
        $(document).on('click','#onpay',function(){
            var id = $(this).data('id');
            $.ajax({
                type : 'POST',
                url  : '<?php echo \think\Request::instance()->root(); ?>/ausagent/Initialization/check',
                dataType : 'json',
                data : {id:id},
                async : false,
                success : function(result){
                    if(0 == result.code){
                        $('#pay').remove();
                        window.location.reload();
                    }else{
                        layer.msg(result.msg, {icon: 5});
                    }
                },
                error : function(){
                    layer.msg("{:lang('服务器错误！请稍后重试')}", {icon: 2});
                }
            }) 
        });

        $(document).on('click','#renew',function(){
            $('#xufei').show();

        });
        $('#queren').click(function(){
            var formdata = $('#myfoms').serialize(); 
            $.ajax({
                type : 'POST',
                url  : '<?php echo \think\Request::instance()->root(); ?>/ausagent/Initialization/addorder',
                dataType : 'json',
                data : formdata,
                async : false,
                success : function(result){
                    if(0 == result.code){
                       // layer.msg(result.msg, {icon: 1});
                        //parent.location.reload();
                        $('#queren').hide();
                        $('#pay').show();
                        $('#qrcode').attr('src',result.msg);
                        $('#onpay').data('id',result.id);
                    }else{
                        layer.msg(result.msg, {icon: 5});
                    }
                },
                error : function(){
                    layer.msg("{:lang('服务器错误！请稍后重试')}", {icon: 2});
                }
            });
        });
    });
    </script>
</body>
</html>